<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>随机打乱一个字符串</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.str-rot13.html">« str_rot13</a></li>
      <li style="float: right;"><a href="function.str-split.html">str_split »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.strings.html">字符串 函数</a></li>
    <li>随机打乱一个字符串</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.str-shuffle" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">str_shuffle</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">str_shuffle</span> &mdash; <span class="dc-title">随机打乱一个字符串</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.str-shuffle-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>str_shuffle</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>): <span class="type">string</span></div>

  <p class="simpara">
   <span class="function"><strong>str_shuffle()</strong></span> 函数打乱一个字符串，使用任何一种可能的排序方案。
  </p>
   <div class="caution"><strong class="caution">警告</strong>
 <p class="para">
  本函数并不会生成安全加密的值，并且<em class="emphasis">不可</em>用于加密或者要求返回值不可猜测的目的。
 </p>
 <p class="para">
  如果需要加密安全随机，则可以将 <span class="classname"><a href="class.random-engine-secure.html" class="classname">Random\Engine\Secure</a></span> 引擎用于
  <span class="classname"><a href="class.random-randomizer.html" class="classname">Random\Randomizer</a></span>。对于简单的用例，<span class="function"><a href="function.random-int.html" class="function">random_int()</a></span>
  和 <span class="function"><a href="function.random-bytes.html" class="function">random_bytes()</a></span> 函数提供了操作系统的 <abbr title="Cryptographically Secure PseudoRandom Number Generator">CSPRNG</abbr> 支持的方便且安全的 <abbr title="Application Programming Interface">API</abbr>。
 </p>
</div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.str-shuffle-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">string</code></dt>

     <dd>

      <p class="para">
       输入字符串。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.str-shuffle-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回打乱后的字符串。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.str-shuffle-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.1.0</td>
       <td>
        内置的随机算法从 libc rand 函数<a href="migration71.incompatible.html#migration71.incompatible.rand-srand-aliases" class="link">更改为</a><a href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html" class="link external">&raquo;&nbsp;梅森旋转</a>伪随机数生成算法。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.str-shuffle-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4830">
    <p><strong>示例 #1 <span class="function"><strong>str_shuffle()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'abcdef'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$shuffled&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">str_shuffle</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;输出类似于:&nbsp;bfdaec<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$shuffled</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.str-shuffle-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="random-randomizer.shufflebytes.html" class="function" rel="rdfs-seeAlso">Random\Randomizer::shuffleBytes()</a> - Get a byte-wise permutation of a string</span></li>
    <li class="member"><span class="function"><a href="random-randomizer.shufflearray.html" class="function" rel="rdfs-seeAlso">Random\Randomizer::shuffleArray()</a> - Get a permutation of an array</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>